<?php
class KeywordsController extends AppController {
	var $name = 'Keywords';
	var $helpers = array('Html');
	var $components = array('Init', 'Param');
	
	function beforeFilter() {
		if (!$this->Session->read('admin')) {
			$this->redirect('/login');
		}
		else {
			$this->Init->startup($this);
			$this->Admin = $this->Init->init();
			
			$this->set('dashboard',1);
			$this->set('content',0);
			$this->set('products',0);
			$this->set('component',0);
			$this->set('system',0);
			
			$this->set('title','Keywords Management');
			$this->set('sub_title', $this->Param->getAction($this->params));
			
  		}
	}
	
	function index(){
		
		$keywords = $this->Keyword->find('all', array(
										'conditions' => array(
											'Keyword.status' => 1
											),
										'order' 	 => 'Keyword.date desc'
										));
		$this->set('keywords',$keywords);
	}
	
	function edit($id = null){
		$id = abs(intval($id));
		
		if ($id < 1) {
			$this->redirect('/keywords');	
		}
		
		$this->set('id', $id);
		
		if (isset($this->data)) {
			$this->data['Keyword']['id'] = $id;
			$this->data['Keyword']['date'] = date('Y-m-d H:i:s');

			if ($this->Keyword->save($this->data['Keyword'])) {
				$this->Session->setFlash('abc');
				$this->redirect('/keywords');
			}
		}
		
		$this->data = $this->Keyword->find('first',	array(
			'conditions' => array('Keyword.id' => $id)
		));
	
	}
	function del($id = null) {
		 $this->Keyword->id = $id;
		 $this->Keyword->delete();
		 $this->Session->setFlash('Dữ liệu đã cập nhật');
		 $this->redirect('/keywords');
	}
	
}
?>